Repository navigation
Add non-blocking task.IsCompleted check - #182
andystaples wants to merge 7 commits into
Conversation
Add task.IsCompleted, which reports whether an orchestration task has succeeded, failed, or been canceled without blocking, consuming its result, or advancing history. The Task interface is unchanged. Custom Task implementations are rejected as in OnTask, and calls outside an orchestration coroutine panic as in Select. Teach the orchestratorgo analyzer that IsCompleted is a pure read and report !task.IsCompleted(t) loops that can never make durable progress. Show a between-checkpoint stop check in the externalevents sample. Fixes #177 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the task completion API and related analyzer updates.
No open issues 🎉
What changed in this PR
Adds task.IsCompleted(t) so orchestrators can check task completion without blocking, consuming results, or advancing history, while preserving the existing Task interface.
Changes:
- Adds the completion check with tests for outcomes, unsupported calls, and replay-position behavior.
- Updates the analyzer to recognize completion checks as pure reads and flag provably non-progressing polling loops.
- Demonstrates stop checks between checkpoints in the external-events sample and documents the API’s limitations.
| File | Description |
|---|---|
task/task.go |
Implements and documents IsCompleted. |
task/task_completion_test.go |
Tests completion states, panic conditions, and replay behavior. |
samples/README.md |
Adds task readiness to the external-events sample description. |
samples/externalevents/README.md |
Explains checkpoint-boundary stop handling. |
samples/externalevents/externalevents.go |
Demonstrates non-blocking stop checks between checkpoints. |
samples/externalevents/externalevents_test.go |
Tests stop ordering and checkpoint errors. |
README.md |
Introduces the completion check and polling limitations. |
cmd/orchestratorvet/README.md |
Documents polling-loop diagnostics and proof constraints. |
cmd/orchestratorvet/analysis/orchestratorgo/testdata/src/loops/loops.go |
Adds polling-loop diagnostic and exclusion cases. |
cmd/orchestratorvet/analysis/orchestratorgo/testdata/src/github.com/microsoft/durabletask-go/task/task.go |
Adds the API stub for analyzer tests. |
cmd/orchestratorvet/analysis/orchestratorgo/loops.go |
Detects non-progressing polling loops and models IsCompleted as pure. |
cmd/orchestratorvet/analysis/orchestratorgo/checks.go |
Passes syntax context into loop analysis. |
CHANGELOG.md |
Records the new API and analyzer behavior. |
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Bernd Verst (berndverst)
left a comment
There was a problem hiding this comment.
IsCompleted adds the readiness check without changing Task or advancing history. I would fix the polling diagnostic before merging: a Go iterator can await durable work and still be reported as a loop that can never make progress.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Bernd Verst (berndverst)
left a comment
There was a problem hiding this comment.
The direct and generic iterator fixes address the original examples, and IsCompleted preserves the existing Task interface and replay behavior. There is one more false positive: slices.Collect can run an iterator that awaits durable work, but vet still reports that the loop cannot make progress.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The callback guard can falsely report yielding polling loops as non-yielding when trusted package calls dispatch user-defined methods, requiring conservative handling and regression coverage.
1 open issue
Review effort: Balanced
| if isFunction(argumentType) || isTypeParameter(argumentType) { | ||
| return true |
Bernd Verst (berndverst)
left a comment
There was a problem hiding this comment.
The iterator fixes now cover direct ranges, generic ranges, and slices.Collect. I reproduced the remaining issue in the method-dispatch thread: fmt.Sprint can call a String method that awaits durable work, but vet still reports that the loop cannot make progress. The diagnostic should stay conservative when a call can invoke user methods.

Fixes #177.
Summary
Adds
task.IsCompleted(t Task) bool, a non-blocking check for whether an orchestration task has completed. A task counts as completed when it succeeded, failed, or was canceled. The check doesn't block, consume the result, or advance history. CallAwaitto read the result or error.Behavior
WhenAnyorSelectwakes on a completion, only the selected task is guaranteed to be complete. Other completions in the same batch become visible after the orchestration waits again.Await,WhenAny, orSelectto wait.Taskinterface is unchanged, so existingTaskimplementations keep compiling.Taskimplementations panic, matchingOnTask,WhenAny, andSelect. Calls outside an orchestration coroutine panic, matchingSelect.WhenAllstill accepts custom tasks while the other helpers reject them. That existing inconsistency is tracked separately in #181 and is out of scope here.Analyzer
The
orchestratorgoanalyzer treatstask.IsCompletedas a pure read instead of possible durable progress. It also reportsfor !task.IsCompleted(t)loops it can prove never make durable progress. The report requirestto be a local variable that the loop never reassigns, whose address is never taken, and that no closure captures. Compound conditions aren't reported.Sample and docs
externaleventssample checks for aStopevent between typed checkpoint receives. A stop request doesn't interrupt a checkpoint wait that is already pending; the sample README points toSelectfor that case.